package com.ossjk.oa.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ossjk.core.util.CommonUtil;
import com.ossjk.oa.system.entity.EmployeePost;
import com.ossjk.oa.system.entity.PostPermission;
import com.ossjk.oa.system.mapper.EmployeePostMapper;
import com.ossjk.oa.system.service.IEmployeePostService;

/**
 * <p>
 * 职工-部门表 服务实现类
 * </p>
 *
 * @author chair
 * @since 2019-01-29
 */
@Service
public class EmployeePostServiceImpl extends ServiceImpl<EmployeePostMapper, EmployeePost> implements IEmployeePostService {

	@Override
	public boolean updatePost(String id, String[] pid) {
		// 删除该用户岗位
		Wrapper wrapper = Condition.create().eq("eid", id);
		this.baseMapper.delete(wrapper);
		if (!CommonUtil.isBlank(pid)) {
			List<EmployeePost> employeePosts = new ArrayList();
			for (String pidStr : pid) {
				EmployeePost employeePost = new EmployeePost();
				employeePost.setEid(id);
				employeePost.setPid(pidStr);
				employeePosts.add(employeePost);
			}
			return this.insertBatch(employeePosts);
		} else {
			return true;
		}

	}

}
